package com.deyuanyun.pic.pipe.controller;

import com.deyuanyun.pic.common.dto.PageJsonBean;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.pipe.controller.dto.IdentificationQuery;
import com.deyuanyun.pic.pipe.controller.vo.IdentificationVO;
import com.deyuanyun.pic.pipe.enumeration.PipeExportEnum;
import com.deyuanyun.pic.pipe.service.PipeMgrService;
import com.deyuanyun.pic.settings.util.DownExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * “地面标识”控制类
 *
 * @author huanglw
 * @date  2016-10-14
 *
 * History: [修改人][时间][修改描述]
 */
@Controller
@RequestMapping("/pipe/identification")
public class IdentificationController extends PipeBaseController {

	@Resource
	private PipeMgrService pipeMgrService;


	/**
	 * 跳转到 地面标识 主页面
	 *
	 * @return
     */
	@RequestMapping("/toIdentification")
	public ModelAndView toIdentificationMgr(){
		ModelAndView mav = new ModelAndView();
		mav.setViewName("/basedata/gis/identificationMgr");
		return mav;
	}

	/**
	 * 根据条件分页查询 地面标识 数组对象
	 *
	 * @param identificationQuery
	 */
	@RequestMapping("/query.json")
	@ResponseBody
	public void query(IdentificationQuery identificationQuery) {
		PageJsonBean jsonBean = new PageJsonBean();
		jsonBean.setList(this.queryVO(identificationQuery));
		AjaxSupport.sendSuccessText("success", jsonBean);
	}

	/**
	 * 根据条件导出 地面标识
	 *
	 * @param identificationQuery
	 * @throws IOException
	 */
	@RequestMapping("/export.json")
	@ResponseBody
	public void export(IdentificationQuery identificationQuery) throws IOException {
		List list = this.queryVO(identificationQuery);
		PipeExportEnum exportEnum = PipeExportEnum.Identification;
		String[] columnKeys = {"pipeLineName", "signNumber", "signType", "mileage", "signStatus", "recorder", "recordTime", "remark"};
		DownExcelUtil.export(exportEnum.getFileName(), pipePath+exportEnum.getTempPath(), exportEnum.getBeginRow(), list, columnKeys);
	}

	private List queryVO(IdentificationQuery identificationQuery) {
		return new IdentificationVO().fromDomainList(pipeMgrService.queryIdentification(identificationQuery));
	}
}
